﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public  class ResponseBase
{

    public const int DefaultSucCode = 0;
    public const int DefaultErrCode = -1;
        
    public RequestBase request;
    protected MessagePacket MessagePacketFrimServer;


    ResponseData m_ResponseData;
    public ResponseData responseData => m_ResponseData;

    public bool Init(MessagePacket messagePacket,RequestBase requestBase)
    {
        MessagePacketFrimServer = messagePacket;
        request = requestBase;

        try
        {
            ResponseData t = requestBase.NewResponseData();
            t.Read(messagePacket.data);
            m_ResponseData = t;
        }
        catch (System.Exception e)
        {
            GameDebug.LogError(e);
            return false;
        }
        return true;
    }
    
   // public abstract void Excuate();
    public  void Excuate()
    {
        this.request.onResponse?.Invoke(this);
    }

}
